package com.sy.simpleegg.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.sy.simpleegg.MainActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class BootReceiver: BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        intent?.run {
            if (action == "android.intent.action.BOOT_COMPLETED"){
                var coroutineScope = CoroutineScope(Dispatchers.IO)
                coroutineScope.launch {
                    delay(3000)
                    val activityIntent = Intent(
                        context,
                        MainActivity::class.java
                    )
                    activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    context?.startActivity(activityIntent)
                }

            }
        }
    }
}